<?php

namespace App\Providers;

use App\Http\Controllers\CartController;
use App\Http\Controllers\WishController;
use App\Models\Procategory;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Validator;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \Validator::extend('mobile',function ($attribute,$value,$parameters,Validator $validator){
            return $validator->validateRegex($attribute,$value,['/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/']);
        });

        view()->composer('*',function ($view){
            $view->with('username',\request()->cookie('usernameCookie'));
        });

        //viewcomposer处理分类导航菜单
        view()->composer('common.header',function ($view){
            $view->with('category',Procategory::where('parent_no','=',0)->get());
        });

        view()->composer('wishpage',function ($view){
            $view->with('mywishs',WishController::getWish());
        });

        view()->composer('cartpage',function ($view){
            $view->with('mycarts',CartController::getCart());
        });


    }
}
